unit setcolmu;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, cxContainer, cxEdit, cxCheckListBox,
  StdCtrls, dxSkinscxPCPainter, 
  cxDataStorage, DB, cxDBData, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  dxSkinsDefaultPainters, dxSkinOffice2010Blue, dxSkinWhiteprint;

type
  TFcolmu = class(TForm)
    cxcheckl: TcxCheckListBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private

    { Private declarations }
  public
  gd:tcxGridDBTableView;
   procedure addcxgrid();

    { Public declarations }
  end;

implementation

{$R *.dfm}

procedure TFcolmu.addcxgrid();
var
  i:integer;
  ts:TcxCheckListBoxItem;
begin
for i:=0 to gd.ColumnCount-1 do
begin

ts:=cxcheckl.Items.add;
ts.Text:=gd.Columns[i].Caption;
if gd.Columns[i].Visible then
ts.Checked:=true;
end;
end;

procedure TFcolmu.Button1Click(Sender: TObject);
var
i:integer;
begin
gd.BeginUpdate();
for i:=0 to cxcheckl.Items.Count-1 do
if cxcheckl.Items[i].Checked then
   gd.Columns[i].Visible:=true
   else
   gd.Columns[i].Visible:=False;
gd.EndUpdate;
end;

procedure TFcolmu.Button2Click(Sender: TObject);
begin
close;
end;

procedure TFcolmu.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=cafree;
end;

end.
